%%--------------------------------------------------------------------
%% Author: <vjache>
%% Created: 30.03.2009
%% Description: Iterator over all keys in an ets table.
%%--------------------------------------------------------------------
-module(iter_ets_keys).

%%--------------------------------------------------------------------
%% Include files
%%--------------------------------------------------------------------
-include("../include/iter.hrl").
%%--------------------------------------------------------------------
%% Exported Functions
%%--------------------------------------------------------------------
-export([
	 new/1,
	 open/1,
	 next/1,
	 close/1,
	 test/1
	]).

%%--------------------------------------------------------------------
%% API Functions
%%--------------------------------------------------------------------

new(Tid) ->
    iter:from_module(?MODULE, Tid).

open(Tid) ->
    {Tid,ets:first(Tid)}.

next({_Tid,'$end_of_table'}=S) ->
    {S,?EOF};
next({Tid,Key}) ->
    NextKey=ets:next(Tid, Key),
    {{Tid,NextKey},Key}.
close(_S) ->
    ok.

%%--------------------------------------------------------------------
%% Test Functions
%%--------------------------------------------------------------------

test(LL) ->
    I=iter:from_module(?MODULE, [iter:from_list(L)||L<-LL]),
    iter:foreach(I,fun(E)->
			   io:format("~p~n",[E])
		   end),
    ok.

%%--------------------------------------------------------------------
%% Local Functions
%%--------------------------------------------------------------------
